{% extends 'base.html' %}

{% block title -%}
{{ build.name }} &rsaquo; API keys
{%- endblock title %}

{% block description -%}
API key management for '{{ build.name }}'
{%- endblock description %}


{% block body %}

<div class="row">
    <div class="span12">
        <h4>Create a new API key</h4>

        {% if create_form.errors %}
            <div class="row">
                <div class="span6 alert alert-error">
                {% for field, field_errors in create_form.errors|dictsort %}
                    <div>
                        Invalid {{ create_form[field].label(class="inline") }}
                    </div>
                {% endfor %}
                </div>
            </div>
        {% endif %}

        <form action="{{ url_for('manage_api_keys') }}" method="post">
            {{ create_form.csrf_token }}
            {{ create_form.build_id }}
            <div>
                {{ create_form.purpose.label }}
                {{ create_form.purpose }}
            </div>
            <br>
            {{ create_form.create(class_='btn btn-primary') }}
        </form>
    </div>
</div>

<div class="row">
    <div class="span12">
        <h4>Existing API keys</h4>
    </div>
</div>

{% if revoke_form_list %}
    {% for api_key, revoke_form in revoke_form_list %}
        <div class="row">
            <div class="span9 well well-small">
                <div class="row">
                    <div class="span7">
                        {% if api_key.superuser %}
                            <div class="row">
                                <div class="span2 text-error">
                                    <strong>Superuser</strong>
                                </div>
                            </div>
                        {% endif %}
                        <div class="row">
                            <div class="span2"><strong>Purpose</strong></div>
                            <div class="span5">{{ api_key.purpose }}</div>
                        </div>
                        <div class="row">
                            <div class="span2"><strong>Created</strong></div>
                            <div class="span5">{{ api_key.created|timesince }}</div>
                        </div>
                        <div class="row">
                            <div class="span2"><strong>Client ID</strong></div>
                            <div class="span5">{{ api_key.id }}</div>
                        </div>
                        <div class="row">
                            <div class="span2"><strong>Client Secret</strong></div>
                            <div class="span5">{{ api_key.secret }}</div>
                        </div>
                    </div>
                    <div class="span2 text-right">
                        {% if not api_key.active %}
                            <div class="text-error">
                                <strong>Revoked</strong>
                            </div>
                        {% else %}
                            <form class="inline-form" action="{{ url_for('revoke_api_key') }}" method="post">
                                {{ revoke_form.csrf_token }}
                                {{ revoke_form.id }}
                                {{ revoke_form.build_id }}
                                {{ revoke_form.revoke(class_='btn btn-inverse btn-small') }}
                            </form>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
    {% endfor %}
{% else %}
    <div class="row">
        <div class="span12">
            There are no API keys for this build.
        </div>
    </div>
{% endif %}


{% endblock body %}
